package com.itany.cloud.controller;

import com.itany.cloud.entity.User;
import com.itany.cloud.service.UserService;
import com.itany.cloud.util.ResponseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * Author:shixiaojun@itany.com
 * Date: 2022/3/22 9:20
 * Version: 1.0-SNAPSHOT
 */
@RestController
@RequestMapping("/users")
public class UserController {

    @Autowired
    private UserService userService;


    @GetMapping
    public ResponseResult findAll(){
        return userService.findAll();
    }

    @GetMapping("/{id}")
    public ResponseResult findById(@PathVariable Integer id){
        return userService.findById(id);
    }

    @PostMapping
    public ResponseResult addUser(User user){
        return userService.addUser(user.getUsername(),user.getPassword(),user.getPhone(),user.getAddress());
    }

    @DeleteMapping("/{id}")
    public ResponseResult deleteUser(@PathVariable Integer id){
        return userService.deleteUser(id);
    }

    @PutMapping
    public ResponseResult modifyUser(User user){
        return userService.modifyUser(user.getId(),user.getUsername(),user.getPassword(),user.getPhone(),user.getAddress());
    }

}
